/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.pig.pigpen.view;

import org.apache.pig.pigpen.util.PigLauncher;
import org.apache.pig.pigpen.util.PigLauncher_2;
import org.eclipse.core.resources.IFile;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;

public class LaunchWindowView extends ViewPart {

    public static final String VIEW_ID = "org.apache.pig.pigpen.view.LaunchWindowView";

    private Text text;
    private ScrolledComposite scrollbar;
    private PigLauncher_2 pigLauncher = null;

    @Override
    public void createPartControl(Composite parent) {
        text = new Text(parent, SWT.MULTI | SWT.READ_ONLY);
        // text.setBounds(10, 10, 100, 200);
        // scrollbar = new ScrolledComposite(parent, SWT.V_SCROLL |
        // SWT.H_SCROLL);
    }

    @Override
    public void setFocus() {
        text.setFocus();
    }

    public void launch(IFile file) {
        this.setPartName("Pig Launch: " + file.getName());

        pigLauncher = new PigLauncher_2(file, text);
        Thread t = new Thread(pigLauncher);
        // pigLauncher.run();
        t.start();

        /*
         * try { t.join(); } catch (InterruptedException e) { // TODO
         * Auto-generated catch block e.printStackTrace(); }
         */
    }

    public void kill() {
//        if (pigLauncher != null) {
//            pigLauncher.kill();
//            pigLauncher = null;
//        }
//        text.append("PigLauncher killed\n");
    }

}
